package com.umiwe.permission.service.impl;


import com.baomidou.mybatisplus.extension.api.R;
import com.umiwe.entity.UmiweRole;
import com.umiwe.entity.UmiweUserRoleVO;
import com.umiwe.entity.UserRoleVO;
import com.umiwe.permission.mapper.UserMapper;
import com.umiwe.permission.mapper.UserRoleMapper;
import com.umiwe.permission.service.UserRoleService;
import com.umiwe.utils.JsonUtils;
import com.umiwe.utils.Result;
import com.umiwe.utils.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class UserRoleServiceImpl implements UserRoleService {

    @Autowired
    private UserRoleMapper userRoleMapper;

    @Autowired
    private UserMapper userMapper;
    /**
     * 通过用户id找到对应角色
     * @param userId
     * @return
     */
    @Override
    public Result getUserRoleById(Integer userId, Integer systemId) {
        UserRoleVO userRoleVO = userRoleMapper.getUserRoleById(userId, systemId);
        if(userRoleVO != null){
            return Result.success(JsonUtils.objectToJson(userRoleVO));
        }else{
            return Result.error(ResultCode.ROLE_ID_NULL);
        }

    }

    /**
     * 查询用户所有的角色
     * @param userId
     * @return
     */
    @Override
    public Result getUserRoleList(Integer userId) {
        return Result.success(JsonUtils.objectToJson(userRoleMapper.getUserRoleList(userId)));
    }

    /**
     * dingId 查询用户id
     * @param dingId
     * @return
     */
    @Override
    public Result getUserDing(String dingId) {
        return Result.success(userMapper.getUserId(dingId));
    }
}
